//package com.epoint.flinkdemo.window;
//
//import com.epoint.flinkdemo.entity.SenSorReader;
//import org.apache.flink.api.common.functions.AggregateFunction;
//import org.apache.flink.api.common.functions.MapFunction;
//import org.apache.flink.api.common.serialization.SimpleStringSchema;
//import org.apache.flink.streaming.api.datastream.DataStream;
//import org.apache.flink.streaming.api.datastream.DataStreamSource;
//import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
//import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
//import org.apache.flink.streaming.api.windowing.time.Time;
//import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer010;
//
//import java.util.Properties;
//
///**
// * @author liufl
// * @version [版本号, 21-4-12]
// */
//public class TimeWindowAggreTest
//{
//    public static void main(String[] args) throws Exception{
//        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
//
//        Properties properties = new Properties();
//        properties.setProperty("bootstrap.servers", "192.168.151.85:9092");
//        //        properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
//        //        properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
//
//        // 从testsource接收数据
////        DataStreamSource<String> kafkaStream = env.addSource(new FlinkKafkaConsumer010<String>("testsource", new SimpleStringSchema(), properties));
//
//        DataStreamSource<String> socketStream = env.socketTextStream("localhost", 7777);
//
//        DataStream<SenSorReader> mapStream = socketStream.map(new MapFunction<String, SenSorReader>()
//        {
//            @Override
//            public SenSorReader map(String value) throws Exception {
//                String[] str = value.split(",");
//                // 时间戳自己造
//                return new SenSorReader(str[0], System.currentTimeMillis(), Double.parseDouble(str[1]));
//            }
//        });
//
//        // 只进行10秒之内进行累加计算
//        mapStream.keyBy("id").timeWindow(Time.seconds(10))
//                .aggregate(new AggregateFunction<SenSorReader, Integer, Integer>()
//                {
//                    @Override
//                    public Integer createAccumulator() {
//                        return 0;
//                    }
//
//                    @Override
//                    public Integer add(SenSorReader value, Integer accumulator) {
//                        return accumulator + 1;
//                    }
//
//                    @Override
//                    public Integer getResult(Integer accumulator) {
//                        return accumulator;
//                    }
//
//                    @Override
//                    public Integer merge(Integer a, Integer b) {
//                        return a + b;
//                    }
//                }).print();
//
//        env.execute();
//    }
//}
